public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        int lenA=0;
        int lenB=0;
        ListNode curA=headA;
        ListNode curB=headB;
        while(curA!=null) {
            lenA++;
            curA=curA.next;
        }
        while(curB!=null) {
            lenB++;
            curB=curB.next;
        }
        ListNode lhead=lenA>lenB?headA:headB;
        ListNode shead=lenA<lenB?headA:headB;
        ListNode curl=lhead;
        ListNode curs=shead;
        int diff=lenA>lenB?lenA-lenB:lenB-lenA;
        for(int i=0;i<diff;i++) {
            curl=curl.next;
        }
        while(curl!=null&&curs!=null) {
            if(curl==curs) {
                return curl;
            }
            curl=curl.next;
            curs=curs.next;
        }
        return null;
    }
}
public class lc160 {
}
